package com.litchi.tutor.controller;

import com.litchi.tutor.common.base.ResponseVO;
import com.litchi.tutor.common.entity.Dict;
import com.litchi.tutor.service.DictService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author xyouzi
 * @date 2021/10/31 12:15
 */
@RestController
@RequestMapping("/dict")
@Api("字典管理")
public class DictController {

    @Autowired
    DictService dictService;

    @RequestMapping(value = "/dict", method = RequestMethod.GET)
    @ApiOperation("根据字典类型查询")
    public ResponseVO getDictByType(String type) {
        List<Dict> dictByType = dictService.getDictByType(type);
        return ResponseVO.ok(dictByType);
    }

    @RequestMapping(value = "/dict", method = RequestMethod.POST)
    @ApiOperation("新增字典")
    public ResponseVO createDict(@RequestBody Dict dict) {
        dictService.createDict(dict);
        return ResponseVO.ok(null);
    }

    @RequestMapping(value = "/dict", method = RequestMethod.PUT)
    @ApiOperation("修改字典")
    public ResponseVO updateDict(@RequestBody Dict dict) {
        dictService.updateDict(dict);
        return ResponseVO.ok(null);
    }

    @RequestMapping(value = "/updateDefault", method = RequestMethod.PUT)
    @ApiOperation("修改字典默认项")
    public ResponseVO updateDefault(Integer id, String type) {
        dictService.updateDefaultOption(id, type);
        return ResponseVO.ok(null);
    }
}
